package com.qhong.modules.controller;

import com.qhong.annotation.LoginUser;
import com.qhong.modules.entity.User;
import com.qhong.modules.response.R;
import com.qhong.util.ServletUtils;
import javax.servlet.http.HttpServletRequest;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created by qhong on 2018/6/1 14:25
 **/
@RestController
@RequestMapping("/user")
public class UserController {

	@RequestMapping(value="/query",method= RequestMethod.GET)
	public User Query(){
		User user=new User();
		user.setAge(22);
		user.setId(1L);
		user.setName("hongdada");
		return user;
	}

	@RequestMapping(value="/query2",method= RequestMethod.POST)
	public User Query2(@LoginUser User u){
		 return u;
	}

	@RequestMapping(value="/add",method= RequestMethod.POST)
	public R AddUser(@RequestBody User user) throws Exception{
		HttpServletRequest req=ServletUtils.getRequest();
		System.out.println("url:"+req.getRequestURI());
		System.out.println("params"+req.getQueryString());
//		BufferedReader br = req.getReader();
//		String str, wholeStr = "";
//		while((str = br.readLine()) != null){
//			wholeStr += str;
//		}
//		System.out.println("body:"+wholeStr);

		R r = new R();
		r.put("code", "000");
		r.put("msg", "Success");
		return r;
	}

}
